package com.gg.user.gguser.controller;

import com.gg.header.getHeaderUser;
import com.gg.user.gguser.service.GgUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
@RequestMapping("/user")
public class GgUserController {

    @Autowired
    private GgUserService ggUserService;

    @Autowired
    RestTemplate restTemplate;

    //用户个人信息查询
    @GetMapping("/getuser")
    public Object getuser(String ggid, HttpServletResponse response, HttpServletRequest request){
        return ggUserService.getUserQ(ggid, response, request);
    }

    // 获取用户列表
    @GetMapping("/getUserAll")
    public Object getUserAll(HttpServletResponse response,Integer page, Integer pacgCount){
        return ggUserService.getUserAll(response,page, pacgCount);
    }

    // 注册 @RequestParam(name = "count" ,required = true)
    /**
     *
     * @param userName  账号
     * @param name 用户名
     * @param passWord  密码
     * @param ZPassWord 验证是否正确密码
     * @param phone 手机号
     * @param mailbox 邮箱
     * @param            invitation  邀请码
     * @return
     */
    @PostMapping("/addUserRegister")
    public Object addUserRegister(HttpServletResponse response,String userName,String name,String passWord,String ZPassWord,String phone,String mailbox,String invitation) throws Exception{
        return ggUserService.addUserRegister(response,userName,name,passWord,ZPassWord,phone,mailbox,invitation);
    }

    // 用户名判断用户是否存在
    @PostMapping("/getUserNameSelectCount")
    public Object getUserNameSelectCount(String userName){
        return ggUserService.getUserNameSelectCount(userName);
    }

    @GetMapping("/hi")
    public Object hi(@RequestParam Integer id){
        Object o = restTemplate.getForObject("http://127.0.0.1:8080/user/getuser?ggid="+id, Object.class);
        return o;
    }

    // 测试获取cookice
    @GetMapping("/hii")
    public Object hii(HttpServletResponse response, HttpServletRequest request,String name) throws IOException {
        Object o = (Object) getHeaderUser.getHader(response,request,name);
        return o;
    }

}
